package com.poetize.plus.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.poetize.plus.entity.dto.page.CommentPageDTO;
import com.poetize.plus.entity.vo.page.CommentPageVO;
import com.poetize.plus.service.CommentService;
import com.poetize.plus.utils.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @author zuosy
 * @created 2024/4/3 14:11
 */
@Tag(name = "评论信息")
@RestController
@RequestMapping("/admin/comment")
@RequiredArgsConstructor
public class CommentController {

    private final CommentService commentService;

    @GetMapping("/commentPage")
    @Operation(summary = "评论分页数据")
    @PreAuthorize(value = "hasRole('administrator')")
    public R<Page<CommentPageVO>> commentPage(CommentPageDTO commentPageDTO){
        return R.ok(commentService.commentPage(commentPageDTO));
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除评论")
    @PreAuthorize(value = "hasRole('administrator')")
    public R<Boolean> deleteComment(@PathVariable("id") Long id){
        return R.ok(commentService.deleteComment(id));
    }
}
